home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
xprolog.arc
/
xprolog.doc
< prev
Wrap
Text File
|
1987-10-12
|
25KB
|
806 lines
X Prolog Vers. 2.0
This software is copyrighted by Andreas Toenne.
It may be copied free of charge iff this copyright notice
is left at it's place.
Andreas Toenne
Computer Science Department
University of Dortmund, W-Germany
E-mail :
atoenne@unido.uucp
atoenne@unido.bitnet
...!seismo!unido!atoenne
***********************************************************
Note ! This manual is just a quick hack to make Xprolog
available as fast as possible.
Sections that are missing are stated in '<' and '>'
Xprolog follows mostly the Cprolog standard, thus the
Cprolog manual could be of some help to the novice user
***********************************************************
1. Getting started.
This program was developed with the Mark Williams C-Compiler Vers. 2.0
It was designed to live on a hard disk!
To start Xprolog simply double click xprolog.ttp without arguments.
Xprolog will try to read it's default image as : C:\BIN\PBOOT
If you don't have this directory or wish to start with another
image, enter the name as an argument for Xprolog.
You may set the enviroment variable BOOTFILE as well.
1.1 Booting XProlog
If you start Xprolog for the very first time, you must create
your own image.
This is done by calling Xprolog with the option -b.
Make sure that the bootfile _boot is present in the current directory.
You may save the image with 'save(Imagename).' then.
1.2 Options
You can specify the sizes of the various data areas with the
following options. The new size must be given in bytes.
-p<size> prototype space
-f<size> functor space
-r<size> number of rules (not bytes!)
-c<size> copystack
-s<size> THE STACK
-t<size> trailstack
The builtin predicate 'statistics' shows the current sizes of
all data areas.
1.3 General
The enviroment variable SHELL may be set if you don't have
msh.prg or want to specify another shell. (cf. 'system', 'sh')
<Control>C may be pressed anytime during computation.
Xprolog performs an abort then. (cf. 'abort')
1.4 Explanation of Data Areas
Prototype: a term in a prolog program
Prototype space: contains all prototypes. Forms a heap.
Rule space: contains descriptors for prolog rules. (clause space)
The rule's terms are kept in the prototype space.
Functor: general descriptor for prolog terms. Contains the name, arity
optional operator definitions and a link to it's rules.
Functors are kept in an avl-tree.
Copystack: keeps copies of prototypes. Grows during unification and
shrinks only upon backtracking.
THE STACK: keeps the computation data that makes up the resolution
tree. Highly dynamic !!
Trailstack: keeps trails (references) for variables that must be
preserved for backtracking. Usually very small.
1.5 Limitations and Default Values
- max. 20 arguments in a term
- max. 50 variables (without anonymous) in a prototype term
- max. 15 open streams
- the reader can read terms upto 8000 bytes
- max. 256 characters in a name
- the cpu stack is 32000 bytes wide
- default shell is 'c:\bin\msh.prg'
- default bootimage is 'c:\bin\pboot'
- default prototype space size is 30000 bytes
- default copystack size if 50000 bytes
- default STACK size is 50000 bytes
- default trailstack size is 800 trail entries
- default number of clauses is 1000
- default functor space is 30000 bytes
2.0 Error Handling and Debugging
2.0.1 Fatal Errors
Fatal errors are :
- not enough memory
- prototype space overflow
- missing main goal to start the machine
- main goal has stopped
- clause space overflow
- missing error goal, iff an recoverable error happens
- functor space overflow
- bad data during boot phase
- invalid prolog image
Fatal errors print an message and terminate Xprolog.
2.0.2 Lesser Errors
These are :
- STACK overflow
- Trailstack overflow
- Copystack overflow
These errors cause an abort of the current goal. (cf. 'abort')
They are usually caused by an loop or by generally insuffient memory.
2.0.3 Recoverable Errors
Recoverable Errors are counted as :
1. Unknown clause.
2. IO failure.
3. Read past EOF.
4. Bad syntax.
5. Too many args/vars.
6. Bad arguments.
7. No valid expression.
8. User break. (control)C
Except error 1 these error are caused by builtin predicates.
They have the following meanings :
1. The current goal refers to an unknown clause. This is normaly due
to a typo or an incomplete program.
2. Some sort of general nastiness. Watch out !!
3. If a read, get, etc. hits the end of the current input stream,
it's argument will be unified with 'end_of_file'.
Note ! This differs from other prolog implementations.
If the programs attemps to read from this stream again, error 3
is the result.
4. This error is due to bad syntax in an prolog term.
Look at the detailed error description of the reader.
5. Xprolog has hard coded limitations for the number of arguments
of a term and the number of variables in a prototype term.
See section 1.5 'Limitations and Default Values'
6. The arguments failed the parameter check for builtins.
7. The user typed <control>C
When an recoverable error occurs, a new goal is set up.
This is 'error(NumberOfTheError, GoalThatCausedTheError)'.
The clause error should normally print a message on the screen and
fail. However it is possible to correct the error and succeed then.
(Note that error 1 should always lead to a failure)
2.1 Debugging Predicates
There are few of them right now.
'debug' switches tracing on.
'nodebug' switches tracing off.
'leash(Value)' sets the amount of tracing data.
The initial value after debug is switched on is 'half'.
The following leash modes exists :
- full trace on call, retry, exit and fail
- tight trace on call, retry and fail
- half trace on call and retry
- loose trace on call
- off no trace
< it is assumed that the reader is familiar with the procedure >
< box control flow model. cf. the prolog primer by Clocksin and >
< Mellish >
3. Reader and Syntax
<far too short>
Generally the reader expects every goal and every program term
to be finished by a dot and a new line!
To read a prolog program (not an image), you should type
'consult(filenameinsinglequotes).'
If you want to read several files you can shorten the command to
'[filename, filename, ...].'. (cf. list syntax)
The goal 'reconsult(filenameinsinglequotes)' rereads clauses.
That means it abolishes the old clauses before asserting them
from the file. (cf. 'abolish' and 'assert')
The same effect is achieved by preceeding the filename in the
short notation by a '-'.
A special file (cf. IO predicates) is 'user'. This stands for
the terminal.
When Xprolog is in the top level loop, it reads goals from
the terminal and tries to satisfy them.
When Xprolog consultes a file, it reads terms and tries to assert
them. You can execute goals by preceeding them by ?- or :- .
The only difference between ?- and :- is, that :- generates no
answer (ie. 'no' or 'yes') and no alternatives are tried.
3.1 Prolog Syntax
3.1.1 Terms
Terms are
- constants
- variables
- structures (generally known as compound terms)
Constants are
- integers (all natural numbers that fit in two machine words)
- atoms (actual atoms are structures without arguments)
The name for an atom must start with a lowercase letter and may
contain any letter, digit and the '_'.
If you want to use any character, you should enclose the name in
single quotes.
< there are some special 'standalone' character which form a >
< valid name. cf. CM 'Programming in Prolog' >
Variables must start with an uppercase letter or with an '_'.
I